package districting;

import java.io.File;
import java.io.IOException;

import de.micromata.opengis.kml.v_2_2_0.Kml;

public class Redistrict {

   /**
    * @param args
    */
   public static void main(String[] args) {
      /*Nation Australia = new Nation("Australia", -45, -10, 110, 155);

      System.out.println("setUpAustralia");
      Australia.setUpAustralia();

      State testState = Australia.getState("QLD");

      System.out.println("import Polling Booth Info");
      AECPollingBoothInfo pbInfoImporter = new AECPollingBoothInfo(Australia);

      AECResultsByPB2010 resultsImporter = new AECResultsByPB2010(Australia);

      Kml kml = KmlFactory.createKml();
      Folder folder = kml.createAndSetFolder().withName(testState.getName())
            .withOpen(true);
      folder.createAndAddStyle().withId("balloonStyle")
            .createAndSetBalloonStyle().withText("$[description]");
      pbInfoImporter.ImportPBInfo(testState);

      System.out.println("setting polling booth polygons");
      testState.setPolygons();

      System.out.println("setting district polygons");
      testState.setAreas(DivisionMethod.STATUS_QUO);

      Australia.printAllDivisionsNames(DivisionMethod.STATUS_QUO);

      System.out.println("import results");
      // resultsImporter.importPrimaryVotes(testState);
      resultsImporter.import2PP(testState);

      System.out.println("calculating current winners");
      Australia.calculateWinners(DivisionMethod.STATUS_QUO);
      System.out.println("current winners calculated");

      Australia.print2PPResult(DivisionMethod.STATUS_QUO);

      Australia.printParliament(DivisionMethod.STATUS_QUO);

      try {
         testState.createBitmap(new ConcretePBPropertyDivision(
               DivisionMethod.STATUS_QUO), testState.getName()
               + "_by_Curr_Division.bmp");
      } catch (IOException e) {
         System.out.println(e.getMessage());
      }

      ShortestBisectingLineMethod sblm = new ShortestBisectingLineMethod(
            Australia);
      sblm.allocateDivisions(testState);

      try {
         testState.createBitmap(new ConcretePBPropertyDivision(
               DivisionMethod.SHORTEST_BISECTING_LINE), testState.getName()
               + "_by_SBLM_Division.bmp");

      } catch (IOException e) {
         System.out.println(e.getMessage());
      }

      System.out.println("calculating sblm winners");
      Australia.calculateWinners(DivisionMethod.SHORTEST_BISECTING_LINE);
      System.out.println("sblm winners calculated");

      Australia.print2PPResult(DivisionMethod.SHORTEST_BISECTING_LINE);

      Australia.printParliament(DivisionMethod.SHORTEST_BISECTING_LINE);

      System.out.println("Redistrict - SBLM Finished");

      VoronoiesqueMethod vorm = new VoronoiesqueMethod(Australia);
      vorm.allocateDivisions(testState);

      try {
         testState.createBitmap(new ConcretePBPropertyDivision(
               DivisionMethod.VORONOIESQUE), testState.getName()
               + "_by_VorM_Division.bmp");

      } catch (IOException e) {
         System.out.println(e.getMessage());
      }

      System.out.println("calculating voronoiesque winners");
      Australia.calculateWinners(DivisionMethod.VORONOIESQUE);
      System.out.println("voronoiesque winners calculated");

      Australia.print2PPResult(DivisionMethod.VORONOIESQUE);

      Australia.printParliament(DivisionMethod.VORONOIESQUE);

      HillClimbingMethod peak = new HillClimbingMethod(Australia,
            DivisionMethod.VORONOIESQUE);
      peak.allocateDivisions(testState);

      try {
         testState.createBitmap(new ConcretePBPropertyDivision(
               DivisionMethod.HILL_CLIMBING), testState.getName()
               + "_by_Peak_Division.bmp");
      } catch (IOException e) {
         System.out.println(e.getMessage());
      }

      System.out.println("calculating hill_climbing winners");
      Australia.calculateWinners(DivisionMethod.HILL_CLIMBING);
      System.out.println("hill_climbing winners calculated");

      Australia.print2PPResult(DivisionMethod.HILL_CLIMBING);

      Australia.printParliament(DivisionMethod.HILL_CLIMBING);

      System.out.println("Converting to KML");

      Document documentBooths = folder.createAndAddDocument().withName(
            testState.getName() + "Booths").withOpen(false);
      testState.toKmlBooths(documentBooths);

      Document documentDivisionsCurr = folder.createAndAddDocument().withName(
            testState.getName() + "DivisionsCurr").withOpen(false);
      testState.toKmlDivisions(documentDivisionsCurr,
            DivisionMethod.STATUS_QUO,);

      Document documentDivisionsSBLM = folder.createAndAddDocument().withName(
            testState.getName() + "DivisionsSBLM").withOpen(false);
      testState.toKmlDivisions(documentDivisionsSBLM,
            DivisionMethod.SHORTEST_BISECTING_LINE);

      Document documentDivisionsVorM = folder.createAndAddDocument().withName(
            testState.getName() + "DivisionsVorM").withOpen(false);
      testState.toKmlDivisions(documentDivisionsVorM,
            DivisionMethod.VORONOIESQUE);

      Document documentDivisionsPeak = folder.createAndAddDocument().withName(
            testState.getName() + "DivisionsHill").withOpen(false);
      testState.toKmlDivisions(documentDivisionsPeak,
            DivisionMethod.HILL_CLIMBING);

      try {
         kml.marshal(new File(testState.getName() + ".kml"));
      } catch (IOException e) {
         System.out.println(e.getMessage());
      }
      System.out.println("Done");
   }*/
      
      Nation Australia = new Nation("Australia", -45, -10, 110, 155);

      System.out.println("setUpAustralia");
      Australia.setUpAustralia();

      System.out.println("import Polling Booth Info");
      AECPollingBoothInfo pbInfoImporter = new AECPollingBoothInfo(Australia);

      AECResultsByPB2010 resultsImporter = new AECResultsByPB2010(Australia);

      pbInfoImporter.ImportPBInfo();

      System.out.println("setting polling booth polygons");
      Australia.setPolygons();

      System.out.println("setting district polygons");
      Australia.setAreas(DivisionMethod.STATUS_QUO);

      Australia.printAllDivisionsNames(DivisionMethod.STATUS_QUO);

      System.out.println("import results");
      // resultsImporter.importPrimaryVotes();
      resultsImporter.import2PP();

      System.out.println("calculating current winners");
      Australia.calculateWinners(DivisionMethod.STATUS_QUO);
      System.out.println("current winners calculated");

      Australia.print2PPResult(DivisionMethod.STATUS_QUO);

      Australia.printParliament(DivisionMethod.STATUS_QUO);

      ShortestBisectingLineMethod sblm = new ShortestBisectingLineMethod(
            Australia);
      sblm.allocateDivisions();

      System.out.println("calculating sblm winners");
      Australia.calculateWinners(DivisionMethod.SHORTEST_BISECTING_LINE);
      System.out.println("sblm winners calculated");

      Australia.print2PPResult(DivisionMethod.SHORTEST_BISECTING_LINE);

      Australia.printParliament(DivisionMethod.SHORTEST_BISECTING_LINE);

      System.out.println("Redistrict - SBLM Finished");

      VoronoiesqueMethod vorm = new VoronoiesqueMethod(Australia);
      vorm.allocateDivisions();

      System.out.println("calculating voronoiesque winners");
      Australia.calculateWinners(DivisionMethod.VORONOIESQUE);
      System.out.println("voronoiesque winners calculated");

      Australia.print2PPResult(DivisionMethod.VORONOIESQUE);

      Australia.printParliament(DivisionMethod.VORONOIESQUE);

      HillClimbingMethod peak = new HillClimbingMethod(Australia,
            DivisionMethod.VORONOIESQUE);
      peak.allocateDivisions();

      System.out.println("calculating hill_climbing winners");
      Australia.calculateWinners(DivisionMethod.HILL_CLIMBING);
      System.out.println("hill_climbing winners calculated");

      Australia.print2PPResult(DivisionMethod.HILL_CLIMBING);

      Australia.printParliament(DivisionMethod.HILL_CLIMBING);

      System.out.println("Converting to KML");

      Kml kml = Australia.toKml();
      try {
         // kml.marshal(new File("Australia.kml"));
         kml.marshal(new File(Australia.getName() + ".kml"));
      } catch (IOException e) {
         System.out.println(e.getMessage());
      }
      System.out.println("Done");
   }

}